package com.baizhi.service.impl;

import com.baizhi.dao.EmpDao;
import com.baizhi.entity.Emp;
import com.baizhi.repository.EmpEsRepository;
import com.baizhi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao ed;
    @Autowired
    private EmpEsRepository eer;
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void insert(Emp emp) {
        ed.insert(emp);
        System.out.println("业务类插入emp后的emp对象，注意观察id属性："+emp);
        eer.insert(emp);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void delete(int id) {
        ed.deleteById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void update(Emp emp) {
        ed.updateById(emp);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Emp> selectAll() {
        return ed.selectList(null);
    }

    @Override
    @Transactional(readOnly = true)
    public Emp selectOne(int id) {
        return ed.selectById(id);
    }

    @Override
    public List<Emp> selectByContent(String content) {
        return eer.selectByContent(content);
    }
}
